home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Control Strip / ES 1.0 Package / Programming Stuff / ExtensionsStrip.p < prev    next >
Encoding:
Text File  |  1995-10-17  |  16.0 KB  |  400 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        ExtensionsStrip.p
  3.  
  4.      Contains:    Extensions Strip Specific Interfaces plus the commented out
  5.                  Universal ControlStrip.p Interfaces.
  6.  
  7.      Version:    Technology:    System 7.1+ (System 7.5+ preferred)
  8.                  Package:    Extensions Strip 1.0
  9.  
  10.      Copyright:    © 1995 by Ammon Skidmore, Skidperfect Software Inc.
  11.                  All rights reserved.
  12.  
  13.      Bugs?:        If you find a problem, or have a criticism (they are welcome)
  14.                  with this file, please inform the author at the following address:
  15.                      Internet:    skidperfect@kagi.com
  16. }
  17.  
  18. {$IFC UNDEFINED UsingIncludes}
  19. {$SETC UsingIncludes := 0}
  20. {$ENDC}
  21.  
  22. {$IFC NOT UsingIncludes}
  23.  UNIT ExtensionsStrip;
  24.  INTERFACE
  25. {$ENDC}
  26.  
  27. {$IFC UNDEFINED __EXTENSIONSSTRIP__}
  28. {$SETC __EXTENSIONSSTRIP__ := 1}
  29.  
  30. {$I+}
  31. {$SETC ExtensionsStripIncludes := UsingIncludes}
  32. {$SETC UsingIncludes := 1}
  33.  
  34.  
  35. {$IFC UNDEFINED __CONTROLSTRIP__}
  36. {$I ControlStrip.p}
  37. {$ENDC}
  38.  
  39. {$IFC UNDEFINED __APPLEEVENTS__}
  40. {$I AppleEvents.p}
  41. {$ENDC}
  42.  
  43.  
  44. {$PUSH}
  45. {$ALIGN MAC68K}
  46. {$LibExport+}
  47.  
  48. CONST
  49. {    sdevInitModule                = 0;}    { initialize the module}
  50. {    sdevCloseModule                = 1;}    { clean up before being closed}
  51. {    sdevFeatures                = 2;}    { return feature bits}
  52. {    sdevGetDisplayWidth            = 3;}    { returns the width of the module's display}
  53. {    sdevPeriodicTickle            = 4;}    { periodic tickle when nothing else is happening}
  54. {    sdevDrawStatus                = 5;}    { update the interface in the Control Strip}
  55. {    sdevMouseClick                = 6;}    { user clicked on the module's display area in the Control Strip}
  56. {    sdevSaveSettings            = 7;}    { saved any changed settings in module's preferences file}
  57. {    sdevShowBalloonHelp            = 8;}    { puts up a help balloon, if the module has one to display}
  58.     sdevInAppContext            = 2000;    {   called only once after the module specifically        }
  59.                                         {   requested to be executed from inside Extension        }
  60.                                         {   Strip's context. NB: you can return the special        }
  61.                                         {   result values.                                        }
  62.                                         {}
  63.     sdevInterceptedEvent        = 2001;    {    if the module returned the sdevInterceptAllEvents    }
  64.                                         {   flag in its features, then this selector            }
  65.                                         {   will get called before _each_ event is processed    }
  66.                                         {   by Extensions Strip.  Meant to be used with            }
  67.                                         {   _SBGetCurrentEvent so each event can be looked at,    }
  68.                                         {   and modified if necessary (to prevent passing.)        }
  69.                                         {   NB: you can return the special result values.        }
  70.                                         {}
  71.     sdevDragAccept                = 2002;    {    return 0 if you accept the current drag, and        }
  72.                                         {   1 if you do not.  Modules that do not have any        }
  73.                                         {   drag handlers will never get this called.            }
  74.                                         {   NB: sdevDragAccept is only called from within        }
  75.                                         {   Extensions Strip's dragTrackingInWindow.  So it        }
  76.                                         {   is recommended to only check if you accept the drag    }
  77.                                         {   from within your dragTrackingEnterWindow, and then    }
  78.                                         {   set a global var that you can pass onto ES.            }
  79.                                         {}
  80.     sdevEventMask                = 2003;    {    if the module returned the sdevInterceptAllEvents    }
  81.                                         {   flag in its features, this selector will get        }
  82.                                         {   called to find the event mask to use.  Return your    }
  83.                                         {   mask as the result value of the sdev call.            }
  84.                                         {   sdevEventMask is called once upon initialization,    }
  85.                                         {   and every time sdevFeaturesChange is requested.        }
  86.  
  87.  
  88. {********************************************************************************************
  89.  
  90.     Features supported by the module.  If a bit is set, it means that feature is supported.
  91.     All undefined bits are reserved for future use by Apple, and should be set to zero.
  92.  
  93. ********************************************************************************************}
  94. {}
  95. {    Tip: if you clear sdevWantMouseClicks and set sdevDontAutoTrack, your module    }
  96. {    will receive clicks and Extensions Strip (plus Desktop Strip) will not            }
  97. {    auto-hilite your module.                                                        }
  98. {}
  99.  
  100. {    sdevWantMouseClicks            = 0;}    { notify the module of mouseDown events}
  101. {    sdevDontAutoTrack            = 1;}    { call the module to do mouse tracking}
  102. {    sdevHasCustomHelp            = 2;}    { module provides its own help messages}
  103. {    sdevKeepModuleLocked        = 3;}    { module needs to be locked in the heap}
  104.     sdevHasDragHandlers            = 31;    {    module has installed a drag tracking and/or            }
  105.                                         {   receive handler in the Strip window.                }
  106.                                         {}
  107.     sdevDontPeriodicTickle        = 30;    {    module does not require any idle time so            }
  108.                                         {   by setting this bit it will never get                }
  109.                                         {   called with the sdevPeriodicTickle                     }
  110.                                         {   selector.  Note that you can set this along            }
  111.                                         {   with the sdevInterceptAllEvents bit (if you want)    }
  112.                                         {   and sdevInterceptedEvent will still get called.        }
  113.                                         {   So be nice and set this to help speed up idle        }
  114.                                         {   time processing.                                    }
  115.                                         {}
  116.     sdevInterceptAllEvents        = 29;    {    module wants to be executed before each                }
  117.                                         {   event passes through Extension Strip's                }
  118.                                         {   jGNE filter.  Because the module is allowed            }
  119.                                         {   to modify every event, there is no more need        }
  120.                                         {   for modules, such as Terminator Strip, to            }
  121.                                         {   install their own jGNE filters!                        }
  122.                                         {   NB: You need to return an event mask when your        }
  123.                                         {   module is called by the sdevEventMask selector.        }
  124.  
  125.  
  126. {********************************************************************************************
  127.  
  128.     Special result values returned by the sdevPeriodicTickle and sdevIconMouseClick selectors.
  129.     If a bit is set, the module can request that a specific function is performed by
  130.     the Control Strip.  A result of zero will do nothing.  All undefined bits are reserved
  131.     for future use by Apple, and should be set to zero.
  132.  
  133. ********************************************************************************************}
  134. {}
  135. {    Note: these values can also be returned by the sdevInAppContext and    }
  136. {    sdevInterceptedEvent selectors.                                        }
  137. {}
  138.  
  139. {    sdevResizeDisplay            = 0;}    { resize the module's display}
  140. {    sdevNeedToSave                = 1;}    { need to save changed settings, when convenient}
  141. {    sdevHelpStateChange            = 2;}    { need to update the help message because of a state change}
  142. {    sdevCloseNow                = 3;}    { close a module because it doesn't want to stay around}
  143.     sdevQueueModule                = 31;    {    module needs to be executed from within                }
  144.                                         {   Extension Strip's context: useful for                }
  145.                                         {   things like sending AppleEvents or                    }
  146.                                         {   creating and tracking new drags.                    }
  147.                                         {}
  148.     sdevFeaturesChange            = 30;    {    module wants to change its feature flags. Useful    }
  149.                                         {   for changing clickable state of the module and        }
  150.                                         {   for locking/unlocking the sdev code.                }
  151.  
  152. {********************************************************************************************
  153.  
  154.     miscellaneous
  155.  
  156. ********************************************************************************************}
  157. {    sdevFileType                = 'sdev';}    { module file and code resource type  }
  158.     sdevFileType                = 'Sdev';    { resource type for module's PPC code }
  159.  
  160. {}
  161.  
  162. {    sdevMenuItemMark            = '•';}
  163.  
  164. {    direction values for SBDrawBarGraph}
  165. {    BarGraphSlopeLeft            = -1;}                            { max end of sloping bar graph is on the left}
  166. {    BarGraphFlatRight            = 0; }                            { max end of flat bar graph is on the right}
  167. {    BarGraphSlopeRight            = 1; }                            { max end of sloping bar graph is on the right}
  168.  
  169. {}
  170.     {}
  171.     gestaltExtensionsStripAttr        = 'CsEs';    {returns Extensions Strip's attributes}
  172.     
  173.     { currently returned bits from gestaltExtensionsStripAttr: }
  174.     gestaltExtensionsStripExists    = 0;    {Extensions Strip is currently launched}
  175.     
  176.     {}
  177.     gestaltDesktopStripAttr            = 'CsWT';    { returns the Mice and Men's Desktop Strip    }
  178.                                                 { attributes which are supported by            }
  179.                                                 { Extensions Strip.  See Desktop Strip's    }
  180.                                                 { documentation for details about the bits    }
  181. {}
  182.  
  183. TYPE
  184.     ModuleReference = LONGINT;
  185.  
  186. {}
  187.  
  188.     SBQueueProcPtr = ProcPtr;  { PROCEDURE SBQueue(refCon: LONGINT); }
  189.     SBQueueUPP = UniversalProcPtr;
  190.  
  191. CONST
  192.     uppQueueProcProcInfo =  $000000C0; { PROCEDURE (4 byte param); }
  193.  
  194. FUNCTION NewSBQueueProcProc(userRoutine: SBQueueProcPtr): SBQueueUPP;
  195.     {$IFC NOT GENERATINGCFM }
  196.     INLINE $2E9F;
  197.     {$ENDC}
  198.  
  199. {}
  200.  
  201. {********************************************************************************************
  202.  
  203.     utility routines to provide standard interface elements and support for common functions
  204.  
  205. ********************************************************************************************}
  206.  
  207. {                                                                                 }
  208. {                                                                                 }
  209. { All routines are documented as to whether the Extensions Strip implementation  }
  210. { of them they may move memory.  You can trust that a routine that says it         }
  211. { will not move memory in this version, will not move memory in future versions. }
  212. { Note though, that some Universal Control Strip traps may move memory under     }
  213. { Control/Desktop Strip but not in Extensions Strip (such as                     }
  214. { _SBIsControlStripVisible and _SBShowHideControlStrip.)                         }
  215. {                                                                                 }
  216. {                                                                                 }
  217.  
  218. { ========================================================= }
  219. { ========== Universal Control Strip traps ================ }
  220. { ========================================================= }
  221.  
  222.             { Will not move memory. }
  223. {FUNCTION SBIsControlStripVisible: BOOLEAN;}
  224.  
  225.             { Will not move memory. }
  226. {PROCEDURE SBShowHideControlStrip(showIt: BOOLEAN);}
  227.  
  228.             { Will not move memory. }
  229. {FUNCTION SBSafeToAccessStartupDisk: BOOLEAN;}
  230.  
  231.             { May move memory! }
  232. {FUNCTION SBOpenModuleResourceFile(fileCreator: OSType): INTEGER;}
  233.  
  234.             { May move memory! }
  235. {FUNCTION SBLoadPreferences(prefsResourceName: ConstStr255Param; VAR preferences: Handle): OSErr;}
  236.  
  237.             { May move memory! }
  238. {FUNCTION SBSavePreferences(prefsResourceName: ConstStr255Param; preferences: Handle): OSErr;}
  239.  
  240.             { Will not move memory. }
  241. {PROCEDURE SBGetDetachedIndString(theString: StringPtr; stringList: Handle; whichString: INTEGER);}
  242.  
  243.             { May move memory! }
  244. {FUNCTION SBGetDetachIconSuite(VAR theIconSuite: Handle; theResID: INTEGER; selector: LONGINT): OSErr;}
  245.  
  246.             { May move memory! }
  247. {FUNCTION SBTrackPopupMenu(VAR moduleRect: Rect; theMenu: MenuHandle): OSErr;}
  248.  
  249.             { May move memory! }
  250. {FUNCTION SBTrackSlider(VAR moduleRect: Rect; ticksOnSlider: INTEGER; initialValue: INTEGER): OSErr;}
  251.  
  252.             { May move memory! }
  253. {FUNCTION SBShowHelpString(VAR moduleRect: Rect; helpString: StringPtr): OSErr;}
  254.  
  255.             { Will not move memory. }
  256. {FUNCTION SBGetBarGraphWidth(barCount: INTEGER): INTEGER;}
  257.  
  258.             { May move memory! }
  259. {PROCEDURE SBDrawBarGraph(level: INTEGER; barCount: INTEGER; direction: INTEGER; barGraphTopLeft: Point);}
  260.  
  261.             { May move memory! }
  262. {PROCEDURE SBModalDialogInContext(filterProc: ModalFilterUPP; VAR itemHit: INTEGER);}
  263.  
  264. { ======================================================= }
  265. { ========== Extensions Strip ONLY traps ================ }
  266. { ======================================================= }
  267.  
  268. { Strip Window Utilities }
  269.  
  270.     { returns: true = vertical; false = horizontal }
  271.     {}        { Will not move memory. }
  272. FUNCTION SBIsControlStripVertical(stripPort: WindowRef): BOOLEAN;
  273.     {$IFC NOT GENERATINGCFM}
  274.     INLINE $70FF, $AAF2;
  275.     {$ENDC}
  276.  
  277.     { returns pixel depth of the monitor this Strip window is in (always a power of 2) }
  278.     {}        { Will not move memory. }
  279. FUNCTION SBGetControlStripDepth(stripPort: WindowRef): INTEGER;
  280.     {$IFC NOT GENERATINGCFM}
  281.     INLINE $70FE, $AAF2;
  282.     {$ENDC}
  283.  
  284.     { returns the current normal back color of this Strip window }
  285.     {}        { Will not move memory. }
  286. PROCEDURE SBGetStripBackColor(VAR color: RGBColor; stripPort: WindowRef);
  287.     {$IFC NOT GENERATINGCFM}
  288.     INLINE $70FD, $AAF2;
  289.     {$ENDC}
  290.  
  291.     { returns the current back color of this Strip window when a module is selected }
  292.     {}        { Will not move memory. }
  293. PROCEDURE SBGetStripSelectedColor(VAR color: RGBColor; stripPort: WindowRef);
  294.     {$IFC NOT GENERATINGCFM}
  295.     INLINE $70FC, $AAF2;
  296.     {$ENDC}
  297.  
  298. { Module Utilities }
  299.  
  300.     { returns a reference number that all of the Module Utilities need                }
  301.         { NB: since SBGetMyReferenceNum can ONLY be called from sdevInitModule,        }
  302.         {   you should save its value into your globals if you are going to use        }
  303.         {   one of the Module Utilities later, such as inside a tracking handler.    }
  304.     { Also, the reference number will always be non-zero. }
  305.     {}        { Will not move memory. }
  306. FUNCTION SBGetMyReferenceNum: ModuleReference;
  307.     {$IFC NOT GENERATINGCFM}
  308.     INLINE $70FB, $AAF2;
  309.     {$ENDC}
  310.  
  311.     { total window space taken up by a module.  Useful for drag-n-drop calculations }
  312.     { note that this rect will always be larger than the module's statusRect. }
  313.     {}        { Will not move memory. }
  314. PROCEDURE SBGetTotalModuleBounds(VAR bounds: Rect; stripPort: WindowRef; moduleRefNum: ModuleReference);
  315.     {$IFC NOT GENERATINGCFM}
  316.     INLINE $70FA, $AAF2;
  317.     {$ENDC}
  318.  
  319.     { returns the statusRect of the module.  Very useful for drag-n-drop routines }
  320.     { because you no longer have to constantly set a global rectangle variable to }
  321.     { hold the current location of the module in the Strip window. }
  322.     {}        { Will not move memory. }
  323. PROCEDURE SBGetModuleBounds(VAR bounds: Rect; moduleRefNum: ModuleReference);
  324.     {$IFC NOT GENERATINGCFM}
  325.     INLINE $70F9, $AAF2;
  326.     {$ENDC}
  327.  
  328. { Miscellaneous Utilities }
  329.  
  330.     { runs this (locked!) piece of code once within Extensions Strip's context.        }
  331.     { PPC modules must pass a valid routine descriptor to this function.  Since        }
  332.     { the descriptor will not be disposed of after the code has executed, I would    }
  333.     { recommend creating the descriptor (NewSBQueueProcProc) when sdevInitModule    }
  334.     { is called and disposing it upon sdevCloseModule.                                }
  335.     { A non-zero result code means that the UPP could not be queued (memory error).    }
  336.     {}        { May move memory! }
  337. FUNCTION SBQueueCode(theProc: SBQueueUPP; refCon: LONGINT): OSErr;
  338.     {$IFC NOT GENERATINGCFM}
  339.     INLINE $70F8, $AAF2;
  340.     {$ENDC}
  341.  
  342.     { sends the specified Apple Event within Extensions Strip's context to insure        }
  343.     { safe sending rather than trusting that the front application is AE aware.            }
  344.     { _SBSimpleAESend acts just like _AESend in that the AppleEvent you give to it        }
  345.     { must still be disposed of afterward by your code to free up memory (even            }
  346.     { though the event hasn't actually been sent yet.)                                    }
  347.     {}
  348.     { _SBSimpleAESend is meant to be an easy way to send simple events.  If you            }
  349.     { need to check the reply AppleEvent or the _AESend error, ect., you should queue    }
  350.     { your code (with _SBQueueCode or by having your module return 'sdevQueueModule')    }
  351.     { and send the Apple Event yourself.  The result returned by _SBSimpleAESend        }
  352.     { is only non-zero if an error occured while queueing the event for later sending.    }
  353.     {}
  354.     { Also, if an error does occur when Extensions Strip sends your AppleEvent, the        }
  355.     { user will be notified with a dialog that _AESend failed.                            }
  356.     {}
  357.     { Here are the parameters I give to _AESend.  They are basic enough for most        }
  358.     { kinds of Apple Events that modules send, hence the name _SBSimpleAESend.            }
  359.     { err := AESend(theAppleEvent, reply,                 your specified AppleEvent        }
  360.     {                                                    { and a dummy reply descriptor    }
  361.     {            kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer,     send mode        }
  362.     {            kAENormalPriority,                                     send priority    }
  363.     {            kAEDefaultTimeout,                                     time out            }
  364.     {            nil,                                                 idleProc            
  365.     {            nil);                                                 filterProc        
  366.     {}        { May move memory! }
  367. FUNCTION SBSimpleAESend({CONST}VAR theAppleEvent: AppleEvent): OSErr;
  368.     {$IFC NOT GENERATINGCFM}
  369.     INLINE $70F7, $AAF2;
  370.     {$ENDC}
  371.  
  372.  
  373.     { returns a pointer to the current event being processed.  Modififations to        }
  374.     { the data in this pointer WILL take effect as the event gets passed along        }
  375.     { to the other processes and jGNE filters further on in the chain.  Although    }
  376.     { a module can use this function at any time, it is really meant to be called    }
  377.     { within the sdevInterceptedEvent selector because this is where a module can    }
  378.     { deny other modules the proper processing of the event (such as in the case    }
  379.     { of a keyDown.)  Another good use for SBGetCurrentEvent() is to find the exact    }
  380.     { point where a mouseDown occured if you have a queue of clickable objects.        }
  381.     {}        { Will not move memory. }
  382. TYPE
  383.     EventRecordPtr = ^EventRecord;
  384. FUNCTION SBGetCurrentEvent: EventRecordPtr;
  385.     {$IFC NOT GENERATINGCFM}
  386.     INLINE $70F6, $AAF2;
  387.     {$ENDC}
  388.  
  389.  
  390. {$ALIGN RESET}
  391. {$POP}
  392.  
  393. {$SETC UsingIncludes := ExtensionsStripIncludes}
  394.  
  395. {$ENDC} {__EXTENSIONSSTRIP__}
  396.  
  397. {$IFC NOT UsingIncludes}
  398.  END.
  399. {$ENDC}
  400.